
#pragma once

#include "zAdAChar.h"
#include "zdbhatch.h"
#include "zAcString.h"

class UcDbSectionSettings;

class UcDbSection : public UcDbEntity
{
public:
    enum State
    {
        kPlane              = (0x1 << 0),
        kBoundary           = (0x1 << 1),
        kVolume             = (0x1 << 2),
    };

    enum SubItem
    {
        kNone               = 0,
        kSectionLine        = (0x1 << 0),
        kSectionLineTop     = (0x1 << 1),
        kSectionLineBottom  = (0x1 << 2),
        kBackLine           = (0x1 << 3),
        kBackLineTop        = (0x1 << 4),
        kBackLineBottom     = (0x1 << 5),
        kVerticalLineTop    = (0x1 << 6),
        kVerticalLineBottom = (0x1 << 7),
    };

    enum Height
    {
        kHeightAboveSectionLine = 0x1,
        kHeightBelowSectionLine = 0x2,
    };

public:
    UCDB_DECLARE_MEMBERS(UcDbSection);

    UCDB_PORT UcDbSection(void);
    UCDB_PORT UcDbSection(const UcGePoint3dArray& pts,
        const UcGeVector3d& verticalDir);
    UCDB_PORT UcDbSection(const UcGePoint3dArray& pts,
        const UcGeVector3d& verticalDir, const UcGeVector3d& vecViewingDir);
    UCDB_PORT ~UcDbSection(void);

    UCDB_PORT UcDbSection::State state      (void) const;
    UCDB_PORT Ucad::ErrorStatus setState    (UcDbSection::State nState);

    UCDB_PORT const ZTCHAR* getName          (void) const;
    UCDB_PORT Ucad::ErrorStatus getName     (UcString& sName) const;
    UCDB_PORT Ucad::ErrorStatus getName     (ZTCHAR*& pszName) const;
    UCDB_PORT Ucad::ErrorStatus setName     (const ZTCHAR* pszName);

    UCDB_PORT UcGeVector3d viewingDirection (void) const;
    UCDB_PORT Ucad::ErrorStatus setViewingDirection(const UcGeVector3d& dir);

    UCDB_PORT UcGeVector3d verticalDirection(void) const;
    UCDB_PORT Ucad::ErrorStatus setVerticalDirection(const UcGeVector3d& dir);

    UCDB_PORT UcGeVector3d normal           (void) const;
    UCDB_PORT Ucad::ErrorStatus plane       (UcGeVector3d& uAxis,
                                             UcGeVector3d& vAxis) const;

    UCDB_PORT int   indicatorTransparency   (void) const;
    UCDB_PORT Ucad::ErrorStatus setIndicatorTransparency(int nTransparency);

    UCDB_PORT UcCmColor indicatorFillColor  (void) const;
    UCDB_PORT Ucad::ErrorStatus setIndicatorFillColor(const UcCmColor& color);

    UCDB_PORT int numVertices               (void) const;
    UCDB_PORT Ucad::ErrorStatus getVertex   (int nIndex,
                                             UcGePoint3d& pt) const;
    UCDB_PORT Ucad::ErrorStatus setVertex   (int nIndex,
                                             const UcGePoint3d& pt);
    UCDB_PORT Ucad::ErrorStatus addVertex   (int nInsertAt,
                                             const UcGePoint3d& pt);
    UCDB_PORT Ucad::ErrorStatus removeVertex(int nIndex);
    UCDB_PORT Ucad::ErrorStatus getVertices (UcGePoint3dArray& pts) const;
    UCDB_PORT Ucad::ErrorStatus setVertices (const UcGePoint3dArray& pts);

    UCDB_PORT double height                 (UcDbSection::Height nHeightType) const;
    UCDB_PORT Ucad::ErrorStatus setHeight   (UcDbSection::Height nHeightType,
                                             double fHeight);

    UCDB_PORT bool  hitTest                 (const UcGePoint3d& ptHit,
                                             int* pSegmentIndex,
                                             UcGePoint3d* ptOnSegment,
                                             UcDbSection::SubItem* pSubItem) const;

    UCDB_PORT Ucad::ErrorStatus createJog   (const UcGePoint3d& ptOnSection);

    UCDB_PORT UcDbObjectId getSettings      (void) const;
    UCDB_PORT Ucad::ErrorStatus getSettings (UcDbSectionSettings*& pSettings,
                                             UcDb::OpenMode mode) const;

    UCDB_PORT bool  isLiveSectionEnabled    (void) const;
    UCDB_PORT Ucad::ErrorStatus enableLiveSection(bool bEnable);

    UCDB_PORT Ucad::ErrorStatus generateSectionGeometry (UcDbEntity *pEnt,
                                UcArray<UcDbEntity*>& intBoundaryEnts,
                                UcArray<UcDbEntity*>& intFillEnts,
                                UcArray<UcDbEntity*>& backgroundEnts,
                                UcArray<UcDbEntity*>& foregroundEnts,
                                UcArray<UcDbEntity*>& curveTangencyEnts) const;

public:

    UCDB_PORT virtual Ucad::ErrorStatus getClassID(CLSID* pClsid) const;
    UCDB_PORT virtual Ucad::ErrorStatus dwgInFields (UcDbDwgFiler* pFiler);
    UCDB_PORT virtual Ucad::ErrorStatus dwgOutFields(UcDbDwgFiler* pFiler) const;
    UCDB_PORT virtual Ucad::ErrorStatus dxfInFields (UcDbDxfFiler* pFiler);
    UCDB_PORT virtual Ucad::ErrorStatus dxfOutFields(UcDbDxfFiler* pFiler) const;
    UCDB_PORT virtual ZSoft::Boolean worldDraw(UcGiWorldDraw* wd);
    UCDB_PORT virtual Ucad::ErrorStatus getGripPoints(UcDbGripDataPtrArray& grips,
                                             const double curViewUnitSize,
                                             const int gripSize,
                                             const UcGeVector3d& curViewDir,
                                             const int bitflags) const;
    UCDB_PORT virtual Ucad::ErrorStatus moveGripPointsAt(const UcDbVoidPtrArray& gripAppData,
                                             const UcGeVector3d& offset,
                                             const int bitflags);
    UCDB_PORT virtual Ucad::ErrorStatus subClose();
    UCDB_PORT virtual Ucad::ErrorStatus getOsnapPoints(UcDb::OsnapMode osnapMode,
                                             ZSoft::GsMarker gsSelectionMark,
                                             const UcGePoint3d& pickPoint,
                                             const UcGePoint3d& lastPoint,
                                             const UcGeMatrix3d& viewXform,
                                             UcGePoint3dArray& snapPoints,
                                             UcDbIntArray & geomIds) const;
    UCDB_PORT virtual Ucad::ErrorStatus transformBy(const UcGeMatrix3d& xform);
    UCDB_PORT virtual void list             (void) const;
    UCDB_PORT virtual Ucad::ErrorStatus getGeomExtents(UcDbExtents& extents) const;
    UCDB_PORT Ucad::ErrorStatus generateSectionGeometry (const UcArray<UcDbEntity*>& entset,
                                UcArray<UcDbEntity*>& intBoundaryEnts,
                                UcArray<UcDbEntity*>& intFillEnts,
                                UcArray<UcDbEntity*>& backgroundEnts,
                                UcArray<UcDbEntity*>& foregroundEnts,
                                UcArray<UcDbEntity*>& curveTangencyEnts) const;

};

class UcDbSectionSettings : public UcDbObject
{
public:
    enum SectionType
    {

        kLiveSection                = (0x1 << 0),
        k2dSection                  = (0x1 << 1),
        k3dSection                  = (0x1 << 2),
    };

    enum Geometry
    {

        kIntersectionBoundary       = (0x1 << 0),
        kIntersectionFill           = (0x1 << 1),
        kBackgroundGeometry         = (0x1 << 2),
        kForegroundGeometry         = (0x1 << 3),
        kCurveTangencyLines         = (0x1 << 4),
    };

    enum Generation
    {

        kSourceAllObjects           = (0x1 << 0),
        kSourceSelectedObjects      = (0x1 << 1),
        kDestinationNewBlock        = (0x1 << 4),
        kDestinationReplaceBlock    = (0x1 << 5),
        kDestinationFile            = (0x1 << 6),
    };

public:
    UCDB_DECLARE_MEMBERS(UcDbSectionSettings);

    UcDbSectionSettings();
    ~UcDbSectionSettings();

    UCDB_PORT virtual Ucad::ErrorStatus getClassID(CLSID* pClsid) const;

    UCDB_PORT Ucad::ErrorStatus reset(void);
    UCDB_PORT Ucad::ErrorStatus reset(UcDbSectionSettings::SectionType nSecType);

    UCDB_PORT UcDbSectionSettings::SectionType currentSectionType(void) const;
    UCDB_PORT Ucad::ErrorStatus setCurrentSectionType(UcDbSectionSettings::SectionType nSecType);

    UCDB_PORT UcDbSectionSettings::Generation generationOptions(UcDbSectionSettings::SectionType nSecType) const;
    UCDB_PORT Ucad::ErrorStatus setGenerationOptions(UcDbSectionSettings::SectionType nSecType,
        UcDbSectionSettings::Generation nOptions);

    UCDB_PORT Ucad::ErrorStatus getSourceObjects(UcDbSectionSettings::SectionType nSecType,
        UcDbObjectIdArray& ids) const;
    UCDB_PORT Ucad::ErrorStatus setSourceObjects(UcDbSectionSettings::SectionType nSecType,
        const UcDbObjectIdArray& ids);

    UCDB_PORT UcDbObjectId destinationBlock(UcDbSectionSettings::SectionType nSecType) const;
    UCDB_PORT Ucad::ErrorStatus setDestinationBlock(UcDbSectionSettings::SectionType nSecType,
        const UcDbObjectId& id);

    UCDB_PORT const ZTCHAR* destinationFile(UcDbSectionSettings::SectionType nSecType) const;
    UCDB_PORT Ucad::ErrorStatus setDestinationFile(UcDbSectionSettings::SectionType nSecType,
        const ZTCHAR* pszFileName);

    UCDB_PORT bool  visibility              (UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry) const;
    UCDB_PORT Ucad::ErrorStatus setVisibility(UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry,
                                             bool bVisible);
    UCDB_PORT UcCmColor color               (UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry) const;
    UCDB_PORT Ucad::ErrorStatus setColor    (UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry,
                                             const UcCmColor& color);
    UCDB_PORT const ZTCHAR* layer            (UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry) const;
    UCDB_PORT Ucad::ErrorStatus setLayer    (UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry,
                                             const ZTCHAR* pszLayer);
    UCDB_PORT const ZTCHAR* linetype         (UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry) const;
    UCDB_PORT Ucad::ErrorStatus setLinetype (UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry,
                                             const ZTCHAR* pszLinetype);
    UCDB_PORT double linetypeScale          (UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry) const;
    UCDB_PORT Ucad::ErrorStatus setLinetypeScale(UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry,
                                             double fScale);
    UCDB_PORT const ZTCHAR* plotStyleName    (UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry) const;
    UCDB_PORT Ucad::ErrorStatus setPlotStyleName(UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry,
                                             const ZTCHAR* pszPlotStyleName);
    UCDB_PORT UcDb::LineWeight lineWeight   (UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry) const;
    UCDB_PORT Ucad::ErrorStatus setLineWeight(UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry,
                                             UcDb::LineWeight nLineWeight);
    UCDB_PORT int   faceTransparency        (UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry) const;
    UCDB_PORT Ucad::ErrorStatus setFaceTransparency(UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry,
                                             int nTransparency);
    UCDB_PORT int   edgeTransparency        (UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry) const;
    UCDB_PORT Ucad::ErrorStatus setEdgeTransparency(UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry,
                                             int nTransparency);
    UCDB_PORT bool  hatchVisibility         (UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry) const;
    UCDB_PORT Ucad::ErrorStatus setHatchVisibility(UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry,
                                             bool bVisible);
    UCDB_PORT Ucad::ErrorStatus getHatchPattern(UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry,
                                             UcDbHatch::HatchPatternType& nPatternType,
                                             const ZTCHAR*& pszPatternName) const;
    UCDB_PORT Ucad::ErrorStatus setHatchPattern(UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry,
                                             UcDbHatch::HatchPatternType nPatternType,
                                             const ZTCHAR* pszPatternName);
    UCDB_PORT double hatchAngle             (UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry) const;
    UCDB_PORT Ucad::ErrorStatus setHatchAngle(UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry,
                                             double fAngle);
    UCDB_PORT double hatchSpacing           (UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry) const;
    UCDB_PORT Ucad::ErrorStatus setHatchSpacing(UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry,
                                             double fSpacing);
    UCDB_PORT double hatchScale             (UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry) const;
    UCDB_PORT Ucad::ErrorStatus setHatchScale(UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry,
                                             double fScale);
    UCDB_PORT bool  hiddenLine              (UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry) const;
    UCDB_PORT Ucad::ErrorStatus setHiddenLine(UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry,
                                             bool bHiddenLine);
    UCDB_PORT bool  divisionLines           (UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry) const;
    UCDB_PORT Ucad::ErrorStatus setDivisionLines(UcDbSectionSettings::SectionType nSecType,
                                             UcDbSectionSettings::Geometry nGeometry,
                                             bool bShow);
};
